package cn.tedu.hotel.serve.controller;

import cn.tedu.hotel.serve.pojo.dto.*;
import cn.tedu.hotel.serve.pojo.vo.*;
import cn.tedu.hotel.serve.service.IHotelIndexService;
import cn.tedu.hotel.serve.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/hotelIndexBanners")
@Api(tags = "10. 前台首页管理模块")
@Validated
public class HotelIndexController {

    @Autowired
    IHotelIndexService hotelIndexService;

    @GetMapping("/user/getUserHotelIndexBannerList")
    @ApiOperation("前台查询全部的轮播图")
    @ApiOperationSupport(order = 400)
    public JsonResult<List<HotelIndexBannerVO>> getUserHotelIndexBannerList(){
        log.debug("开始处理【前台查询全部的轮播图】的请求");
        List<HotelIndexBannerVO> list = hotelIndexService.getAdminHotelIndexBannerList();
        return JsonResult.ok(list);
    }

    @GetMapping("/user/getHotelOrderCountList")
    @ApiOperation("前台查询酒店的排名")
    @ApiOperationSupport(order = 401)
    public JsonResult<List<HotelOrdersCountInfoVO>> getHotelOrderCountList(){
        log.debug("开始处理【前台查询酒店的排名】的请求");
        List<HotelOrdersCountInfoVO> list = hotelIndexService.getHotelOrderCountList();
        return JsonResult.ok(list);
    }

    @PostMapping("/admin/addHotelIndexBanner")
    @ApiOperation("后台添加前台首页轮播图")
    @PreAuthorize("hasAuthority('adminRoot')")
    @ApiOperationSupport(order = 500)
    public JsonResult<Void> addHotelScore(
           HotelIndexBannerDTO hotelIndexBannerDTO
    ){
        log.debug("开始处理【后台添加前台首页轮播图,路径：{}】的请求",hotelIndexBannerDTO);
        hotelIndexService.addHotelIndexBanner(hotelIndexBannerDTO);
        return JsonResult.ok();
    }

    @PostMapping("/admin/{id:[0-9]+}/updateAdminHotelIndexBannerById")
    @ApiOperation("后台根据id修改前台首页轮播图")
    @PreAuthorize("hasAuthority('adminRoot')")
    @ApiOperationSupport(order = 700)
    public JsonResult<Void> updateAdminHotelIndexBannerById(
           @PathVariable @Range(min = 1,message = "请提交有效值") Long id,
           HotelIndexBannerDTO hotelIndexBannerDTO
    ){
        log.debug("开始处理【后台根据id：{}修改前台首页轮播图,路径：{}】的请求",id,hotelIndexBannerDTO);
        hotelIndexService.updateAdminHotelIndexBannerById(id,hotelIndexBannerDTO);
        return JsonResult.ok();
    }

    @GetMapping("/admin/getAdminHotelIndexBannerList")
    @ApiOperation("后台查询全部的轮播图")
    @PreAuthorize("hasAuthority('adminRoot')")
    @ApiOperationSupport(order = 800)
    public JsonResult<List<HotelIndexBannerVO>> getAdminHotelIndexBannerList(){
        log.debug("开始处理【后台查询全部的轮播图】的业务");
        List<HotelIndexBannerVO> list = hotelIndexService.getAdminHotelIndexBannerList();
        return JsonResult.ok(list);
    }

    @PostMapping("/admin/{id:[0-9]+}/deleteAdminHotelIndexBanner")
    @ApiOperation("后台根据轮播图id删除轮播图")
    @PreAuthorize("hasAuthority('adminRoot')")
    @ApiOperationSupport(order = 600)
    public JsonResult<Void> deleteAdminHotelIndexBanner(
            @PathVariable @Range(min = 1,message = "请提交有效值")Long id
    ){
        log.debug("开始处理【后台根据轮播图id：{}删除轮播图】的请求",id);
        hotelIndexService.deleteAdminHotelIndexBanner(id);
        return JsonResult.ok();
    }

}
